package com.yubest.demo.controller;

import com.yubest.demo.anno.Log;
import com.yubest.demo.anno.Type;
import com.yubest.demo.dto.Response;
import com.yubest.demo.dto.UserReqDTO;
import com.yubest.demo.dto.UserRespDTO;
import com.yubest.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author hweiyu
 * @Description
 * @Date 2021/3/1 14:01
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * @return
     */
    @Log(desc = "修改用户信息，将姓名从 #{#userService.get(#reqDTO.id).getUserName()} 修改为 #{#reqDTO.userName}",
            type = Type.UPDATE,
            bizNo = "#{#reqDTO.id}")
    @PutMapping(value = "/update")
    public Response<Void> update(@RequestBody UserReqDTO reqDTO) {
        userService.update(reqDTO);
        return Response.success();
    }

    @Log(desc = "查询用户信息，用户id为 #{#id}", bizNo = "#{#id}")
    @GetMapping(value = "/get/{id}")
    public Response<UserRespDTO> get(@PathVariable("id") Long id) {
        return Response.success(userService.get(id));
    }

}
